package cn.zh.npro.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;


import cn.zh.npro.Item.GItem;
import cn.zh.npro.R;

/**
 * Created by WYN on 2018/1/15 0015.
 */

public class GdAdapter extends BaseAdapter{

    Context context;
    ArrayList<GItem> arrayList;
    LayoutInflater inflater;
    public GdAdapter(Context context, ArrayList<GItem> arrayList){
        this.context=context;
        this.arrayList=arrayList;
        inflater=LayoutInflater.from(context);
       }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
      }


    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (null==view){
            holder=new Holder();
            view=inflater.inflate(R.layout.gp_layout,null,false);
            holder.gimga=view.findViewById(R.id.gimga);

            holder.gname=view.findViewById(R.id.gname);
            holder.guint=view.findViewById(R.id.guint);
            holder.gprice=view.findViewById(R.id.gprice);
            view.setTag(holder);
        }else {
            holder= (Holder) view.getTag();
        }
        if (arrayList.get(i).getIndexURL().equals("")){
            Picasso.with(context).load(R.mipmap.noimage).into(holder.gimga);
        }else {
            Picasso.with(context).load(arrayList.get(i).getIndexURL()).into(holder.gimga);
           }
        holder.gname.setText(arrayList.get(i).getGoodsName());
        holder.guint.setText("单位"+arrayList.get(i).getUnit());
        holder.gprice.setText("¥"+arrayList.get(i).getPrice_Detail());

        return view;
    }


    public class Holder{
      ImageView gimga;
      TextView gname,guint,gprice;
    }







}
